home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C04 / CppLibTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1.1 KB  |  41 lines

  1. //: C04:CppLibTest.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. //{L} CppLib
  7. // Test of C++ library
  8. #include "CppLib.h"
  9. #include "../require.h"
  10. #include <fstream>
  11. #include <iostream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. int main() {
  16.   Stash intStash;
  17.   intStash.initialize(sizeof(int));
  18.   for(int i = 0; i < 100; i++)
  19.     intStash.add(&i);
  20.   for(int j = 0; j < intStash.count(); j++)
  21.     cout << "intStash.fetch(" << j << ") = "
  22.          << *(int*)intStash.fetch(j)
  23.          << endl;
  24.   // Holds 80-character strings:
  25.   Stash stringStash;
  26.   const int bufsize = 80;
  27.   stringStash.initialize(sizeof(char) * bufsize);
  28.   ifstream in("CppLibTest.cpp");
  29.   assure(in, "CppLibTest.cpp");
  30.   string line;
  31.   while(getline(in, line))
  32.     stringStash.add(line.c_str());
  33.   int k = 0;
  34.   char* cp;
  35.   while((cp =(char*)stringStash.fetch(k++)) != 0)
  36.     cout << "stringStash.fetch(" << k << ") = "
  37.          << cp << endl;
  38.   intStash.cleanup();
  39.   stringStash.cleanup();
  40. } ///:~
  41.